package www.dianbaozu.com.ui.server

import android.os.Bundle
import android.view.View
import dagger.hilt.android.AndroidEntryPoint
import www.dianbaozu.com.R
import www.dianbaozu.com.databinding.FragmentJoiningServerBinding
import www.wen.com.common.lib.base.fragment.BaseLoadingFragment
import www.wen.com.common.lib.base.module.BaseViewModel
import www.wen.com.common.lib.extension.getColorAgency
import www.wen.com.common.lib.extension.nav
import www.wen.com.common.lib.extension.toast
import www.wen.com.common.lib.extension.trimProxy
import www.wen.com.common.lib.helper.loading.KeyHelper.BUNDLE_DATA
import www.wen.com.common.lib.helper.loading.TitleBarUniversalAdapter


/**
 * @author WEN
 * @Description:加入服务器
 * @date 2020//25 17:48
 */
@AndroidEntryPoint
class JoiningServerFragment : BaseLoadingFragment<FragmentJoiningServerBinding>(), View.OnClickListener {

    override val viewModel: BaseViewModel
        get() = BaseViewModel()

    override fun isEnableLoadingHelper() = true

    override fun getTitleBarUniversalAdapter(): TitleBarUniversalAdapter = TitleBarUniversalAdapter(
            requireActivity(),
            tilte = getString(R.string.joining_the_server),
            isShowRightText = true,
            rightText = getString(R.string.invitation_code),
            rightTextColor = getColorAgency(R.color.colorFFFFFF),
            action = ::titleAction
    )

    override fun getLayoutId(): Int = R.layout.fragment_joining_server

    override fun lazyInitView() {
        dataBinding.etInputServerName.setOnEditorActionListener { _, _, _ ->
            if(dataBinding.etInputServerName.trimProxy().isNotBlank()){
                nav(R.id.action_joiningServerFragment_to_searchServerFragment, Bundle().apply {
                    putString(BUNDLE_DATA,dataBinding.etInputServerName.trimProxy())
                })
                return@setOnEditorActionListener true
            }
            toast(getString(R.string.Enter_server_name_server_ID))
            return@setOnEditorActionListener false
        }
    }

    override fun actionRight() {
        nav(R.id.action_joiningServerFragment_to_inviteJoiningServerFragment)
    }

}



